package com.cmbchina.warehouse.packaging.antiCorruption.shipping;

import com.cmbchina.warehouse.packaging.entity.Item;
import com.cmbchina.warehouse.packaging.entity.Package;
import com.cmbchina.warehouse.packaging.entity.Warehouse;
import com.cmbchina.warehouse.packaging.service.ILegacyPackagingService;

import java.util.ArrayList;
import java.util.List;

/**
 * 打包服务实现
 *
 * 通过门面模式，将遗留系统包装服务的验证、打包和优化三个步骤组合为一个打包服务
 */
public class PackagingServiceFacade implements IPackagingServiceFacade{
    private ILegacyPackagingService legacyPackagingService;
    public PackagingServiceFacade(ILegacyPackagingService legacyPackagingService) {
        this.legacyPackagingService = legacyPackagingService;
    }

    @Override
    public List<Package> packageItems(List<Item> items, Warehouse warehouse) {
        //验证
        if (legacyPackagingService.validateItemDimensions (items)) {
            //打包
            List<Package> packages = legacyPackagingService.packageItems (items, warehouse);
            //优化
            List<Package> optimizedPackages = legacyPackagingService.optimizePackaging (packages);
            return optimizedPackages;
        }
        return new ArrayList<>();
    }
}
